package com.capgemini.fs.app.ekms.persistence.dao.implementations;

import java.util.List;

import com.capgemini.fs.app.ekms.model.Functionality;
import com.capgemini.fs.app.ekms.model.Role;
import com.capgemini.fs.app.ekms.persistence.dao.RoleDAO;

public class RoleDAOImpl extends BaseDAOHibernateImpl<Role> implements RoleDAO {

	public void addFunctionalityToRole(Role role, Functionality functionality) {
		role.getFunctionalities().add(functionality);
		update(role);
	}

	@SuppressWarnings("unchecked")
	public Role getRoleByName(String name) {
		String hql = "from Role r where r.name=?";
		List<Role> list = (List<Role>) getHibernateTemplate().find(hql, name);
		return list.isEmpty()?null:(Role) list.get(0);
	}

}
